<%--
  User: 19079,Date: 2020/12/17,time: 18:00
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title>缺陷类型设置</title>
    <base href="<%=request.getContextPath()%>/">
    <link rel="stylesheet" href="webjars/layui/2.5.5/css/layui.css">
</head>
<body>
<div>
    <table id="QXtype" lay-filter="QXtype"></table>
</div>
<%--修改和删除按钮--%>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<%--添加和授权按钮--%>
<script type="text/html" id="add">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add" onclick="add()">添加</button>
    </div>
</script>
<%--添加表单弹出层--%>
<div id="addf" style="display: none">
    <form class="layui-form" lay-filter="addf" style="padding: 40px"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-form-item">
            <label class="layui-form-label">缺陷类型名称:</label>
            <div class="layui-input-block">
                <input type="text" name="configvaluename"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用:</label>
            <div class="layui-input-block">
                <input type="hidden" name="isstart1">
                <input type="checkbox"  name="isstart"lay-text="ON|OFF"  lay-skin="switch">
            </div>
        </div>
    </form>
</div>
<%--修改表单弹出层--%>
<div id="up" style="display: none">
    <form class="layui-form" lay-filter="up" style="padding: 40px"> <!-- 提示：如果你不想用form，你可以换成div等任何一个普通元素 -->
        <div class="layui-form-item">
            <label class="layui-form-label">缺陷类型名称:</label>
            <div class="layui-input-block">
                <input type="hidden" name="id">
                <input type="text" name="configvaluename"  class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否启用</label>
            <div class="layui-input-block">
                <input type="hidden" name="isstart1">
                <input type="checkbox"  name="isstart"lay-text="ON|OFF"  lay-skin="switch">
            </div>
        </div>
    </form>
</div>
</body>
<script src="webjars/layui/2.5.5/layui.js"></script>
<script>
    layui.use(["table",'element'],function () {
        let table=layui.table;
        table.render({
            elem:"#QXtype",
            id:"QXtype",
            even:true,
            url:"qx/xqlxsz/getAll",
            toolbar:"#add",
            page:true,
            limit:5,
            limits:[5,10,15],
            toolbar:"#add",
            cols:[[
                {title:"缺陷类型名称",field:"configvaluename"},
                {title: "是否启用",templet:function (row) {
                        return row.isstart==1?"启用":"禁用";
                    }},
                {title: "操作",toolbar: "#barDemo"}
            ]]
        });
       table.on("tool(QXtype)",function ({data,event}){
           switch (event){
               case "update":
                   update(data);
                   break;
               case "del":
                   layui.layer.confirm("确定要删除？",function (index){
                       layui.layer.close(index);
                       del(data.id);
                   });
                   break;
           };
       });
    });
    function add(){
        layui.use(["layer",'jquery'],function (){
            let $=layui.$;
            let layer=layui.layer;
            $("#addf form")[0].reset();
            layer.open({
                type:1,
                content:$("#addf"),
                btn:["确定","取消"],
                yes(){
                    let a=layui.form.val('addf');
                    if ($(".layui-form-switch em").text()=="ON"){
                        a.isstart=1;
                    }else {
                        a.isstart=0;
                    }
                    console.log(a);
                    $(".layui-form-switch").removeClass("layui-form-onswitch");
                    layer.close(layer.index);
                    $.post("qx/xqlxsz/add",a).done(({msg})=>{
                        layer.msg(msg);
                        layui.table.reload("QXtype");
                    });
                }
            });
        });
    };
    function del(id){
        layui.use(['layer','jquery'],function (){
           layui.$.post("qx/xqlxsz/del",{"id":id}).done(({msg})=>{
                layui.layer.msg(msg);
                layui.table.reload("QXtype");
            });
        })
    }
    function update(data){
        layui.use(['form','layer','jquery'],function () {
            let layer=layui.layer;
            let $=layui.$;
            layui.form.val('up',data);
            layer.open({
                type:1,
                content:$("#up"),
                btn: ["确定","取消"],
                area: '500px',
                yes() {
                    let a=layui.form.val("up");
                    if ($(".layui-form-switch em").text()=="OFFON"){
                        a.isstart=1;
                    }else {
                        a.isstart=0;
                    }
                    $(".layui-form-switch").removeClass("layui-form-onswitch");
                    //console.log(a);
                    layer.close(layer.index);
                    $.post("qx/xqlxsz/update",a).done(({msg})=>{
                        layer.msg(msg);
                        layui.table.reload("QXtype");
                    });
                }
            });
        });
    }
</script>
</html>
